<template>
  <div class="app-container">
    <el-dialog :title="pageTitle" :visible.sync="dialogFormVisible" :before-close="beforeClose">
      <el-form :model="form">
        <el-form-item label="店铺名称：" :label-width="formLabelWidth">
          <el-input v-model="form.title" minlength="2" maxlength="10" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="店铺描述：" :label-width="formLabelWidth">
          <el-input v-model="form.describe" minlength="2" maxlength="10" placeholder="请输入店铺描述" />
        </el-form-item>
        <el-form-item label="负责人：" :label-width="formLabelWidth">
          <el-input v-model="form.name" placeholder="请输入负责人名字" />
        </el-form-item>
        <el-form-item label="联系方式：" :label-width="formLabelWidth">
          <el-input v-model="form.phone" placeholder="请输入联系方式" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="canel">取 消</el-button>
        <el-button type="primary" @click="sure">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { handle } from '@/api/store'
export default {
  name: 'StoreHandle',
  data() {
    return {
      form: {
        id: 'new',
        title: '',
        describe: '',
        name: '',
        phone: ''
      },
      formLabelWidth: '120px',
      dialogFormVisible: false,
      parentMenus: [],
      pageTitle: '添加菜单'
    }
  },

  methods: {
    beforeClose() {
      this.canel()
    },

    add() {
      this.form.id = 'new'
      this.pageTitle = '添加店铺'
      this.dialogFormVisible = true
    },

    edit(item) {
      this.form.id = item.id
      this.form.title = item.title
      this.form.describe = item.describe
      this.form.name = item.name
      this.form.phone = item.phone
      this.pageTitle = '编辑 [' + this.form.id + ':' + this.form.title + '] 店铺'
      this.dialogFormVisible = true
    },

    canel() {
      this.dialogFormVisible = false
      this.form.id = 'new'
      this.form.title = ''
      this.form.describe = ''
      this.form.name = ''
      this.form.phone = ''
    },

    sure() {
      handle(this.form).then(res => {
        Message({
          message: res.data.info,
          type: 'success',
          duration: 2000
        })
        this.$emit('afterSave')
        this.canel()
      })
    }

  }
}
</script>
